package com.acme.bankapp.domain.bank;

import java.util.ArrayList;

import com.acme.bankapp.exceptions.bank.ClientExistsException;
import com.acme.bankapp.exceptions.bank.NotEnoughFundsException;
import com.acme.bankapp.sc.bank.BankServer;
import com.acme.bankapp.service.bank.BankDataLoaderService;
import com.acme.bankapp.service.bank.BankService;

import static com.acme.bankapp.service.bank.BankService.readBank;
import static com.acme.bankapp.service.bank.BankService.saveBank;
import static com.acme.bankapp.service.bank.BankService.printBank;
import static com.acme.bankapp.service.bank.BankService.addClient;
import static com.acme.bankapp.service.bank.BankService.addAccount;
import static com.acme.bankapp.service.bank.BankDataLoaderService.clientArrayList;

;

public class BankApplication {

	public static void modifyBank(Bank bank, int idOfClient,
			String depositOrWithdraw, int numOfAccount, int sum)
			throws NotEnoughFundsException {

		ArrayList<Client> clients = bank.getClients();
		if (!(depositOrWithdraw.equals("deposit") || depositOrWithdraw
				.equals("withdraw")) || clients.size() < idOfClient + 1) {
			throw new IllegalArgumentException("IllegalArgumentException");
		} else if (clients.get(idOfClient).getAccounts().size() < numOfAccount + 1) {
			throw new IllegalArgumentException("IllegalArgumentException");
		} else {
			if (depositOrWithdraw.equals("deposit")) {
				clients.get(idOfClient).getAccounts().get(numOfAccount)
						.deposit(sum);
			} else if (depositOrWithdraw.equals("withdraw"))
				clients.get(idOfClient).getAccounts().get(numOfAccount)
						.withdraw(sum);
		}
		saveBank(bank);
	}

	public static void main(String[] args) {
		BankServer bs = new BankServer("C:\\Bank.txt");
		bs.startServer();

	}
}
